/**
 * 
 */
package t4j.concurrency;

import java.io.IOException;

class UnresponsiveUI{
	private volatile double d = 1;
	
	public UnresponsiveUI() throws IOException {
		while(d > 0)
			d = d+ (Math.PI + Math.E) / d;
		
		System.in.read();//never gets here
	}
}


public class ResponsiveUI extends Thread{
	
	private static volatile double d = 1;
	 
	public ResponsiveUI() {
		setDaemon(true);//设为后台线程
		
		start();
	}
	
	public void run(){
		while(true)
			d = d+ (Math.PI + Math.E) / d;
	}
	
	public static void main(String[] args) throws IOException {
		
		//new UnresponsiveUI();//must kill this process
		new ResponsiveUI();
		System.in.read();//main线程等待读入，输入回车后继续下一步
		System.out.println(d);
	}
}
